import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
import {
    menus
} from "./api/login.js"

//路由懒加载
// const about = () =>
//     import ('./views/About.vue')
// const users = () =>
//     import ( /* webpackChunkName: "Welcome" */ './views/users.vue')
// const roles = () =>
//     import ( /* webpackChunkName: "Welcome" */ './views/roles.vue')
// const rights = () =>
//     import ( /* webpackChunkName: "Welcome" */ './views/rights.vue')
// const goods = () =>
//     import ( /* webpackChunkName: "Welcome" */ './views/goods.vue')
// const params = () =>
//     import ( /* webpackChunkName: "Welcome" */ './views/params.vue')

// const categories = () =>
//     import ( /* webpackChunkName: "Welcome" */ './views/categories.vue')
// const orders = () =>
//     import ( /* webpackChunkName: "Welcome" */ './views/orders.vue')
// const reports = () =>
//     import ( /* webpackChunkName: "Welcome" */ './views/reports.vue')
const page = () =>
    import ( /* webpackChunkName: "Welcome" */ './views/page.vue')
    // const add = () =>
    //     import ( /* webpackChunkName: "Welcome" */ './views/add.vue')
console.log(page, "page");


Vue.use(Router)

var routes = [{
        path: '/',
        name: 'home',
        component: Home,
    },
    {
        path: '/about',
        name: 'about',
        component: () =>
            import ('./views/About.vue'),
        redirect: '/page',
        children: [
            // {
            //         path: '/users',
            //         name: 'users',
            //         component: users
            //     },
            //     {
            //         path: '/roles',
            //         name: 'roles',
            //         component: roles
            //     },
            //     {
            //         path: '/rights',
            //         name: 'rights',
            //         component: rights
            //     },
            //     {
            //         path: '/goods',
            //         name: 'goods',
            //         component: goods
            //     },
            //     {
            //         path: '/params',
            //         name: 'params',
            //         component: params
            //     },
            //     {
            //         path: '/categories',
            //         name: 'categories',
            //         component: categories
            //     }, {
            //         path: '/orders',
            //         name: 'orders',
            //         component: orders
            //     },
            //     {
            //         path: '/reports',
            //         name: 'reports',
            //         component: reports
            //     },
            {
                path: '/page',
                name: 'page',
                component: page
            },
            //     {
            //         path: '/add',
            //         name: 'add',
            //         component: add
            //     },

        ]

    },


]



const router = new Router({
    routes
})

function fn1(data) {
    let arr = []

    function deep(data) {
        data.forEach(item => {
            if (item.children.length) {
                console.log("digui");
                deep(item.children)
            } else {
                arr.push({
                    path: `/${item.path}`,
                    name: item.path,
                    component: () =>
                        import (`./views/${item.path}.vue`),
                })
            }
        })
    }
    deep(data)
    return arr
}
async function fn() {
    let {
        data
    } = await menus()
    let list = fn1(data.data)
    return list

}
console.log(fn(), "00");

export default router